    package HardwareConfiguration;  
    import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;  
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;  
 import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;  


    public class HardwareConfiguration_1_2 extends Composite 
    {  
        private Table table;  
        /** 
         * Create the composite 
         * @param parent 
         * @param style 
         */  
        public HardwareConfiguration_1_2(Composite parent, int style) 
        {  
            super(parent, style);  
            setSize(1000, 800);
    		setLayout(new GridLayout(3,true));
    		new Label(this, SWT.NONE);
    		
    		Label label = new Label(this, SWT.NONE);//标题
    		label.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false, 1, 1));
    		label.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
    		//label.setBounds(10, 10, 180, 24);
    		label.setText("硬件配置-隔离约束");
    		new Label(this, SWT.NONE);
    		
    		Label label_1 = new Label(this, SWT.NONE);
    		label_1.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    		label_1.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
    		//label_1.setBounds(10, 55, 331, 24);
    		label_1.setText("请在下表中配置资源所需隔离约束条件：");
    		new Label(this, SWT.NONE);
    		new Label(this, SWT.NONE);
    		
    		// table的初始化
    		table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION);
    		table.setHeaderVisible(true);
    		table.setLinesVisible(true);
    		//table.setItemCount(ITEM_COUNT);
    		//table.setBounds(10, 10, 400, 300);
    		GridData gd_table = new GridData(SWT.FILL,SWT.FILL,true,true,3,1);
    		gd_table.heightHint = 504;
    		table.setLayoutData(gd_table);
    		
    		
    		//设置表1纵坐标
    				/*TableItem[] items = new TableItem[ITEM_COUNT];
    				//for (int i = 0; i < ITEM_COUNT; i++) {
    				//items[i] = new TableItem(table, SWT.CENTER);
    					//columns[i].setText("Column "+new Integer(i+1).toString());
    					//columns[i].setWidth(COLUMN_WIDTH);
    				}*/
    		
    		
    		TableItem tableItem_1 = new TableItem(table, SWT.NONE);
    		tableItem_1.setText("设备1");
    				
    		TableItem tableItem_2 = new TableItem(table, SWT.NONE);
    		tableItem_2.setText("设备2");
    				
    		TableItem tableItem_3 = new TableItem(table, SWT.NONE);
    		tableItem_3.setText("设备3");
    		
    		TableItem tableItem_4 = new TableItem(table, SWT.NONE);
    		tableItem_4.setText("设备4");
    		
    		TableItem tableItem_5 = new TableItem(table, SWT.NONE);
    		tableItem_5.setText("...");
    				
    		TableItem tableItem_6 = new TableItem(table, SWT.NONE);
    		tableItem_6.setText(new String[] {});
    		tableItem_6.setText("设备14");
    		
    		
    		
    				/*设置表1横坐标
    		TableColumn[] columns = new TableColumn[COLUMN_COUNT];
    		for (int i = 0; i < COLUMN_COUNT; i++) {
    			columns[i] = new TableColumn(table, SWT.CENTER);
    		
    		 }*/
    		
    		TableColumn tableColumn_1 = new TableColumn(table, SWT.NONE);
    		tableColumn_1.setWidth(100);
    		tableColumn_1.setText("");
    		
    		TableColumn tableColumn_2 = new TableColumn(table, SWT.NONE);
    		tableColumn_2.setWidth(100);
    		tableColumn_2.setText("设备类型");
    		
    		TableColumn tableColumn_3 = new TableColumn(table, SWT.NONE);
    		tableColumn_3.setWidth(106);
    		tableColumn_3.setText("隔离设备1");
    		
    		TableColumn tableColumn_4 = new TableColumn(table, SWT.NONE);
    		tableColumn_4.setWidth(100);
    		tableColumn_4.setText("隔离设备2");
    		
    		TableColumn tableColumn_5 = new TableColumn(table, SWT.NONE);
    		tableColumn_5.setWidth(100);
    		tableColumn_5.setText("隔离设备3");
    		
    		TableColumn tableColumn_6 = new TableColumn(table, SWT.NONE);
    		tableColumn_6.setWidth(100);
    		tableColumn_6.setText("隔离设备4");
    		
    		//设置按钮
    		Button button_1 = new Button(this, SWT.NONE);
    		button_1.addSelectionListener(new SelectionAdapter() {
    			@Override
    			public void widgetSelected(SelectionEvent e) {
    			}
    		});
    		button_1.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1));
    		button_1.setText("返回");
    		
    				
    		Button button_2 = new Button(this, SWT.NONE);
    		button_2.addSelectionListener(new SelectionAdapter() {
    			@Override
    			public void widgetSelected(SelectionEvent e) {
    			}
    		});
    		button_2.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1));
    		button_2.setText("导出为文件");
    				
    						
    				
    		Button button_3 = new Button(this, SWT.NONE);
    		button_3.addSelectionListener(new SelectionAdapter() {
    			@Override
    			public void widgetSelected(SelectionEvent e) {
    			}
    		});
    		button_3.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1));
    		button_3.setText("保存");
    		
    		
    		table.addListener(SWT.MouseDoubleClick, listener);
        }
        
        
        private Listener listener = new Listener() {
    		private int EDITABLECOLUMN;

    		public void handleEvent(Event event) {
    			//获取鼠标点击的位置
    			Point point = new Point(event.x, event.y);
    		
    			//得到鼠标点击的行（item）
    			TableItem item = table.getItem(point);
    			if (item == null) {
    				return;
    			}
    			for (int i = 1; i < 6; i++) {
    				
    				//得到选中行（item）的每一列的矩形范围，根据鼠标点击位置point来进一步确定是哪一格（cell）
    				Rectangle rect = item.getBounds(i);
    				if (rect.contains(point)) {
    					EDITABLECOLUMN = i;
    					
    					final TableEditor editor = new TableEditor(table);
    					Control oldEditor = editor.getEditor();
    					if (oldEditor != null)
    					{
    						oldEditor.dispose();
    					}
    					
    					// 添加Text，并使高度符合item的高度
    					final Text text = new Text(table, SWT.NONE);
    					text.computeSize(SWT.DEFAULT,table.getItemHeight());

    					//调整editor的高度宽度
    					editor.grabHorizontal = true;
    					editor.minimumHeight = text.getSize().y;
    					editor.minimumWidth = text.getSize().x;
    					
    					editor.setEditor(text, item, EDITABLECOLUMN);
    					
    					text.setText(item.getText(EDITABLECOLUMN));

    					text.forceFocus();
    					
    					// 开始编辑的事件
    					text.addModifyListener(new ModifyListener() {
    						public void modifyText(ModifyEvent e) {
    							editor.getItem().setText(EDITABLECOLUMN,text.getText());
    						}
    					});
    					
    					//编辑后内容恢复表格前景色
    					text.addFocusListener(new FocusAdapter() {
    						public void focusLost(FocusEvent e) {
    						}
    					});
    				}
    			}
    		}
    	};
        @Override  
        protected void checkSubclass() {  
            // Disable the check that prevents subclassing of SWT components  
        }  
    }  